package com.example.controller;

import com.example.common.Result;
import com.example.dto.LoginDTO;
import com.example.service.LoginService;
import com.example.vo.LoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 */
@RestController
@Tag(name = "登录管理", description = "登录相关接口")
public class LoginController {

    @Autowired
    private LoginService loginService;
    
    /**
     * 员工登录
     *
     * @param loginDTO 登录信息
     * @return 登录结果
     */
    @PostMapping("/login")
    @Operation(summary = "员工登录", description = "根据用户名和密码进行登录")
    @ApiResponse(responseCode = "200", description = "登录成功", 
                content = @Content(mediaType = "application/json", 
                schema = @Schema(implementation = Result.class)))
    public Result<LoginVO> login(
            @Parameter(description = "登录信息", required = true) 
            @RequestBody LoginDTO loginDTO) {
        // 调用登录服务
        LoginVO loginVO = loginService.login(loginDTO);
        
        // 判断登录是否成功
        if (loginVO != null) {
            // 登录成功
            return Result.success(loginVO);
        } else {
            // 登录失败
            return Result.error("用户名或密码错误");
        }
    }
} 